﻿<%@ WebHandler Language="C#" Class="lists" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using Newtonsoft.Json.Linq;
using System.Collections;


public class lists : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";

        string onlyId = context.Request.Headers["X-ACCESS-USER"];//Header中的token


        var id=HttpContext.Current.Request.Form["data"];



        if (string.IsNullOrEmpty(id))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }

        var code = 1;
        var msg = "获取成功";
        var time = DateTime.Now;


        using (Entities bll = new Entities())
        {
            int _id = int.Parse(id);


            ArrayList listclass = new ArrayList();

            var good = bll.S_Goods.SingleOrDefault(x=>x.GID==_id).childClassId;//全部.ToList();
            var Bpl = bll.S_Goods.Where(x=>x.childClassId==good).OrderBy(x=>x.GSort).ToList();//全部.ToList();



            DateTime kstime = DateTime.Now;
            ArrayList listjson = new ArrayList();
            foreach (var x in Bpl)
            {
                var singTime = "";
                var currentState = 0;

                var iconPath = "/img/ico/" + x.GSort + ".png";
                //var ispoint = bll.P_T_Sign.FirstOrDefault(s=>s.TaskID==x.GID&&s.UserId==openid);
                var ispoint = bll.P_T_Sign.FirstOrDefault(s=>s.TaskID==x.GID&&s.UserId==onlyId &&s.State ==1);


                if (ispoint != null)
                {
                    iconPath = "/img/icoa/" + x.GSort + ".png";
                    singTime = ispoint.addtime.ToString();
                    currentState = 1;


                    if (kstime> ispoint.addtime)
                        kstime =Convert.ToDateTime(ispoint.addtime);

                }

                var imgs = methods.GetImgs(x.GImg);
                listjson.Add(new
                {
                    id=x.GID,
                    name=x.GName,
                    latitude=x.Glatitude,
                    longitude=x.Glongitude,
                    iconPath,
                    singTime,
                    width=30,
                    height=30,
                    img=imgs,
                    description=x.G_Introduce,
                    currentState,
                    state=currentState,

                    startTime=DateTime.Now.AddDays(-1).ToString("yyyy/MM/dd HH:mm:ss"),
                    endTime=DateTime.Now.AddDays(2).ToString("yyyy/MM/dd HH:mm:ss"),
                    signTime=DateTime.Now.AddDays(2).ToString("yyyy/MM/dd HH:mm:ss"),
                    x.JF,
                    mydistance=x.distance


                });

            };


           // var myendTime = kstime.AddDays(2);


            var dktime = kstime.AddDays(2).ToString("yyyy/MM/dd HH:mm:ss");



            var shortName = "广科";

            context.Response.Write(JsonConvert.SerializeObject(new { code, msg,dktime, time, task=listjson,shortName  }));

        }

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");


    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }




}